package util;

import com.example.bbang.entity.User;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;

public class CreateJwt {
    public static String gettoken(User user){
        //Jwts.builder()生成
        //Jwts.parser()验证
        JwtBuilder jwtBuilder = Jwts.builder()
                .setId(user.getUserID()+"")
                .setSubject(user.getUsername())
                .setIssuedAt(new Date())//登陆时间
                .signWith(SignatureAlgorithm.HS512,"my-123").setExpiration(new Date(new Date().getTime()+43200000));//过期时间半天
        System.out.println(jwtBuilder.compact());
        return  jwtBuilder.compact();

    }
}
